'use strict';

const Controller = require('egg').Controller;

class UsersController extends Controller {
    async index() {
        const data = await this.ctx.service.users.findAll(this.ctx);
        this.ctx.body = data;
    }
    async show() {
        const ctx = this.ctx;
        const userId = ctx.params.id;
        // ctx可能是app文件夹
        // ctx.service.users 能获取到service里的users.find函数
        const user = await ctx.service.users.find(userId);
        ctx.body = user;
    }
    async create(){
        const ctx = this.ctx
        const params = ctx.request.body
        console.log(params)
        const data = await ctx.service.users.create(params);
        ctx.body = data
    }
    async distroy(){
        const userId = this.ctx.params.id;
        const data = await this.ctx.service.users.delete(userId)
        this.ctx.body = data
    }
    /*
    Controller 与页面有关
    service 和数据库对接
1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
    */ 
}

module.exports = UsersController;

